package com.sip.stream.gbstack;

import android.os.Build;
import androidx.core.app.NotificationCompat;
import androidx.vectordrawable.graphics.drawable.PathInterpolatorCompat;
import com.blankj.utilcode.constant.CacheConstants;
import com.google.gson.annotations.SerializedName;
import com.sip.stream.gbstack.Model.GS28181AudioParams;
import com.sip.stream.gbstack.Model.GS28181VideoParams;

import kotlin.UByte;

public class GS28181SDKConfig implements Cloneable {

    public static final String GS28181SDK_DATE_FORMAT = "yyyy-MM-dd'T'HH:mm:ss";

    //本地端口
    @SerializedName("localPort")
    private int localPort = 5061;
    //本地IP
    @SerializedName("localIP")
    private String localIP = "";
    //GB deviceId
    @SerializedName("deviceGBCode")
    private String deviceGBCode = "";
    //GB 设备名称
    @SerializedName("deviceName")
    private String deviceName = "Sip-SDK";
    //制造商
    @SerializedName("manufacturer")
    private String manufacturer = "WX: 7087213";
    //型号
    private String model = null;
    //固件版本
    @SerializedName("firmware")
    private String firmware = "V.1.0.101";
    //作者
    private String owner = "WX: 7087213";
    //设备信息
    private String civilCode = "civilCode";
    private String block = "block";
    private String address = "";
    private String parentID = "";
    private String endTime = "";
    private String certNum = "";
    private String devicePassword = "";
    //地址
    @SerializedName("ipAddress")
    private String ipAddress = "";
    //端口
    @SerializedName("port")
    private int port = 5555;

    private int parental = 0;
    //安全类型
    private int safetyWay = 0;
    private int registerWay = 1;
    private int certifiable = 0;
    private int cerErrCode = 0;
    private int secrecy = 0;
    //GB ID
    @SerializedName("serverGBCode")
    private String serverGBCode = "34020000002000000001";
    //服务器 IP
    @SerializedName("serverIP")
    private String serverIP = "";
    //服务器 端口
    @SerializedName("serverPort")
    private int serverPort = 5060;
    //通道数量
    private int channel = 1;
    //视频编码ID 5: H265 2: H264
    @SerializedName("videoCodeID")
    private int videoCodeID = 2;
    //PPI值
    @SerializedName("ppi")
    private int ppi = 5;
    //帧率
    @SerializedName("frameRate")
    private int frameRate = 25;
    //RTP MTU
    @SerializedName("rtpNetMtu")
    private int rtpNetMtu = 1200;
    //码率类型： 1:固定码率 2: 动态码率
    private int rateType = 1;
    //码率大小： 默认1024
    @SerializedName("rateSize")
    private int rateSize = 1024;
    //音频编码ID 1： G711A  5: G711U  4： G722_1   2： G7231  3：G729
    @SerializedName("audioCodeID")
    private int audioCodeID = 1;
    //采样率
    private int sample = 1;
    //比特率
    private int bitRate = 8;
    //流传输类型： TCP: 2  UDP : 0
    @SerializedName("streamTranType")
    private int streamTranType = 2;
    //心跳周期
    @SerializedName("heardbeat")
    private int heardbeat = 60;
    //注册有效期
    @SerializedName("registertime")
    private int registertime = 3600;
    //平台ID
    @SerializedName("PlatformID")
    private String platformID = "";
    //定位频率
    @SerializedName("locationRate")
    private int locationRate = 3000;
    //定位停止频率
    @SerializedName("positionStopRate")
    private long positionStopRate = 15;
    //设备状态频率
    @SerializedName("deviceStatesRate")
    private int deviceStatesRate = 10000;
    //账户
    @SerializedName("account")
    private String account = "admin";
    //密码
    @SerializedName("password")
    private String password = "7087213";
    //视频通道ID
    @SerializedName("videoChannelID")
    private String videoChannelID = "64020000001315100077";
    //视频通道名称
    @SerializedName("videoChannelName")
    private String videoChannelName = "back_camera";
    //音频通道ID
    @SerializedName("audioChannelID")
    private String audioChannelID = "64020000001315100077";
    //音频通道名称
    @SerializedName("audioChannelName")
    private String audioChannelName = "audioOut";
    //音频通道ID
    @SerializedName("sosChannelID")
    private String sosChannelID = "";
    //报警通道名称
    @SerializedName("sosChannelName")
    private String sosChannelName = "alarm";
    //信令传输协议  TCP: 2 UDP : 1
    @SerializedName("cmdTranType")
    private int cmdTranType = 1;
    //自动推送定位
    @SerializedName("uploadGps")
    private boolean uploadGps = true;
    //自动应答
    @SerializedName("autoAnswer")
    private boolean autoAnswer = true;
    //自动同步配置
    @SerializedName("autoSyncConfig")
    private boolean autoSyncConfig = false;
    //GB28181 版本
    @SerializedName("GB28181Version")
    private int GB28181Version = 2;
    //配置版本
    @SerializedName("configVersion")
    private String configVersion = null;

    //调试模式
    private boolean isDebug = true;

    private boolean isStringEmpty(String str) {
        return str == null || str.trim().isEmpty();
    }

    public GS28181VideoParams getVideoParams() {
        GS28181VideoParams gS28181VideoParams = new GS28181VideoParams();
        gS28181VideoParams.videoCodeID = this.videoCodeID;
        gS28181VideoParams.ppi = this.ppi;
        gS28181VideoParams.frameRate = this.frameRate;
        gS28181VideoParams.rateType = this.rateType;
        gS28181VideoParams.rateSize = this.rateSize;
        return gS28181VideoParams;
    }

    public GS28181AudioParams getAudioParams() {
        GS28181AudioParams gS28181AudioParams = new GS28181AudioParams();
        gS28181AudioParams.audioCodeID = this.audioCodeID;
        gS28181AudioParams.sample = this.sample;
        gS28181AudioParams.bitRate = this.bitRate;
        return gS28181AudioParams;
    }

    public GS28181SDKConfig m156clone() {
        try {
            return (GS28181SDKConfig) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
            return null;
        }
    }

    public int getLocalPort() {
        int i = this.localPort;
        if (i < 1 || i > 65535) {
            return 5060;
        }
        return i;
    }

    public String getDeviceGBCode() {
        return this.deviceGBCode;
    }

    public void setVideoChannelID(String str) {
        this.videoChannelID = str;
    }

    public void setAudioChannelID(String str) {
        this.audioChannelID = str;
    }

    public void setSosChannelID(String str) {
        this.sosChannelID = str;
    }

    public String getDeviceName() {
        return this.deviceName;
    }

    public String getManufacturer() {
        return this.manufacturer;
    }

    public String getModel() {
        if (!isStringEmpty(this.model)) {
            return this.model;
        }
        return Build.MODEL;
    }

    public String getFirmware() {
        return this.firmware;
    }

    public String getOwner() {
        return this.owner;
    }

    public String getCivilCode() {
        return this.civilCode;
    }

    public String getBlock() {
        return this.block;
    }

    public String getAddress() {
        return this.address;
    }

    public String getParentID() {
        return this.parentID;
    }

    public String getEndTime() {
        return this.endTime;
    }

    public String getCertNum() {
        return this.certNum;
    }

    public String getDevicePassword() {
        return this.devicePassword;
    }

    public String getIpAddress() {
        return this.ipAddress;
    }

    public int getPort() {
        return this.port;
    }

    public int getParental() {
        return this.parental;
    }

    public int getSafetyWay() {
        return this.safetyWay;
    }

    public int getRegisterWay() {
        return this.registerWay;
    }

    public int getCertifiable() {
        return this.certifiable;
    }

    public int getCerErrCode() {
        return this.cerErrCode;
    }

    public int getSecrecy() {
        return this.secrecy;
    }

    public String getServerGBCode() {
        return this.serverGBCode;
    }

    public String getServerIP() {
        return this.serverIP;
    }

    public int getServerPort() {
        return this.serverPort;
    }

    public int getChannel() {
        return this.channel;
    }

    public void setLocalIP(String localIP) {
        this.localIP = localIP;
    }

    public String getLocalIP() {
        return this.localIP;
    }

    public boolean isDebug() {
        return this.isDebug;
    }

    public int getStreamTranType() {
        return this.streamTranType;
    }

    public int getHeardbeat() {
        int i = this.heardbeat;
        if (i > 100) {
            return 60;
        }
        return i;
    }

    public int getRegistertime() {
        return this.registertime;
    }

    public String getAccount() {
        return this.account;
    }

    public String getPassword() {
        return this.password;
    }

    public String getPlatformID() {
        return this.platformID;
    }

    public int getLocationRate() {
        return this.locationRate;
    }

    public long getPositionStopRate() {
        return this.positionStopRate;
    }

    public int getDeviceStatesRate() {
        return this.deviceStatesRate;
    }

    public String getSosChannelName() {
        return this.sosChannelName;
    }

    public String getSosChannelID() {
        return this.sosChannelID;
    }

    public String getAudioChannelName() {
        return this.audioChannelName;
    }

    public String getAudioChannelID() {
        return this.audioChannelID;
    }

    public int getAudioCodeID() {
        return this.audioCodeID;
    }

    public String getVideoChannelName() {
        return this.videoChannelName;
    }

    public int getVideoCodeID() {
        return this.videoCodeID;
    }

    public String getVideoChannelID() {
        return this.videoChannelID;
    }

    public int getCmdTranType() {
        return this.cmdTranType;
    }

    public boolean isAutoAnswer() {
        return this.autoAnswer;
    }

    public boolean isUploadGps() {
        return this.uploadGps;
    }

    public int getRtpNetMtu() {
        return this.rtpNetMtu;
    }

    public void setRtpNetMtu(int i) {
        this.rtpNetMtu = i;
    }

    public boolean isAutoSyncConfig() {
        return this.autoSyncConfig;
    }

    public void setAutoSyncConfig(boolean z) {
        this.autoSyncConfig = z;
    }

    public int getGB28181Version() {
        return this.GB28181Version;
    }

    public void setGB28181Version(int i) {
        this.GB28181Version = i;
    }

    public int getPpi() {
        return this.ppi;
    }

    public int getFrameRate() {
        return this.frameRate;
    }

    public int getRateSize() {
        return this.rateSize;
    }

    public void setRateSize(int i) {
        this.rateSize = i;
    }

    public String getConfigVersion() {
        return this.configVersion;
    }

    public void setConfigVersion(String str) {
        this.configVersion = str;
    }

    public static class Builder {
        protected GS28181SDKConfig buildTarget;
        private String errorMessage;

        public Builder() {
            this.errorMessage = "";
            this.buildTarget = GS28181SDK.getInstance().getConfig().m156clone();
        }

        public Builder(GS28181SDKConfig gS28181SDKConfig) {
            this.errorMessage = "";
            this.buildTarget = gS28181SDKConfig.m156clone();
        }

        public GS28181SDKConfig build(GS28181SDKCallBack<GS28181SDKConfig> gS28181SDKCallBack) {
            String str = this.errorMessage;
            if (str == null || str.length() <= 0) {
                GS28181SDK.getInstance().setConfig(this.buildTarget);
                if (gS28181SDKCallBack != null) {
                    gS28181SDKCallBack.onComplete(new GS28181Result<>(this.buildTarget));
                }
                return this.buildTarget;
            } else if (gS28181SDKCallBack != null) {
                gS28181SDKCallBack.onComplete(new GS28181Result<>(-1, this.errorMessage));
                return null;
            } else {
                return null;
            }
        }

        public GS28181SDKConfig clearConfig() {
            this.buildTarget = new GS28181SDKConfig();
            GS28181SDK.getInstance().setConfig(this.buildTarget);
            GS28181SDK.getInstance().saveConfig();
            return this.buildTarget;
        }

        public GS28181SDKConfig getBuildTarget() {
            return this.buildTarget;
        }

        public void commit(GS28181SDKCallBack<GS28181SDKConfig> gS28181SDKCallBack) {
            String str = this.errorMessage;
            if (str != null && str.length() > 0) {
                if (gS28181SDKCallBack != null) {
                    gS28181SDKCallBack.onComplete(new GS28181Result<>(-1, this.errorMessage));
                    return;
                }
                return;
            }
            GS28181SDK.getInstance().setConfig(this.buildTarget);
            GS28181SDK.getInstance().saveConfig();
            if (gS28181SDKCallBack != null) {
                gS28181SDKCallBack.onComplete(new GS28181Result<>(this.buildTarget));
            }
        }

        public Builder setLocalPort(int localPort) {
            if (localPort >= 1 && localPort <= 65535) {
                this.buildTarget.localPort = localPort;
                return this;
            }
            this.errorMessage += "localPort 端口号格式不正确\n";
            return this;
        }

        public Builder setLocalIP(String localIP) {
            this.buildTarget.localIP = localIP;
            return this;
        }

        public Builder setGB28181Version(int GB28181Version) {
            this.buildTarget.GB28181Version = GB28181Version;
            return this;
        }

        public Builder setDeviceGBCode(String deviceGBCode) {
            this.buildTarget.deviceGBCode = deviceGBCode;
            return this;
        }

        public Builder setRtpNetMtu(int rtpNetMtu) {
            if (rtpNetMtu >= 100 && rtpNetMtu <= 1400) {
                this.buildTarget.rtpNetMtu = rtpNetMtu;
                return this;
            }
            this.errorMessage += "mtu not value\n";
            return this;
        }

        public Builder setDeviceBaseInfo(String deviceName, String str2, String model, String firmware, String configVersion) {
            this.buildTarget.deviceName = deviceName;
            this.buildTarget.model = model;
            this.buildTarget.firmware = firmware;
            this.buildTarget.configVersion = configVersion;
            return this;
        }

        public Builder setDeviceOwnerInfo(String owner, String json, String block, String civilCode) {
            this.buildTarget.owner = owner;
            this.buildTarget.block = block;
            this.buildTarget.civilCode = civilCode;
            return this;
        }

        public Builder setServerGBCode(String serverGBCode) {
            this.buildTarget.serverGBCode = serverGBCode;
            return this;
        }

        public Builder setServerParams(String serverGBCode, String serverIP, int serverPort) {
            if (serverPort >= 1 && serverPort <= 65535) {
                this.buildTarget.serverGBCode = serverGBCode;
                this.buildTarget.serverIP = serverIP;
                this.buildTarget.serverPort = serverPort;
                return this;
            }
            this.errorMessage += "serverPort 端口号格式不正确\n";
            return this;
        }

        public Builder setRegisterWay(int registerWay) {
            this.buildTarget.registerWay = registerWay;
            return this;
        }

        public Builder setSafetyWay(int safetyWay) {
            this.buildTarget.safetyWay = safetyWay;
            return this;
        }

        public Builder setCmdTranType(int cmdTranType) {
            this.buildTarget.cmdTranType = cmdTranType;
            return this;
        }

        public Builder setHeardbeat(int heardbeat) {
            if (heardbeat < 0) {
                this.errorMessage += "心跳时间设置不正确\n";
            }
            this.buildTarget.heardbeat = heardbeat;
            return this;
        }

        public Builder setRegistertime(int registertime) {
            if (registertime < 0) {
                this.errorMessage += "过期时间设置不正确\n";
            }
            this.buildTarget.registertime = registertime;
            return this;
        }

        public Builder setCertInfo(String endTime, String certNum, int certifiable, int cerErrCode, int secrecy) {
            if (certNum.length() > 0 && endTime.length() < 1) {
                this.errorMessage += "endTime 有证书的设备必填 证书终止有效期\n";
                return this;
            } else if (secrecy != 0 && secrecy != 1) {
                this.errorMessage += "secrecy 保密属性必须为 0不涉密 1涉密\n";
                return this;
            } else if (certifiable == 0 || certifiable == 1) {
                this.buildTarget.endTime = endTime;
                this.buildTarget.certNum = certNum;
                this.buildTarget.certifiable = certifiable;
                this.buildTarget.cerErrCode = cerErrCode;
                this.buildTarget.secrecy = secrecy;
                return this;
            } else {
                this.errorMessage += "certifiable 证书有效标志必须为 0不涉密 1涉密\n";
                return this;
            }
        }

        public Builder setDeviceCatalogInfo(String parentID, String devicePassword, String ipAddress, int port, int parental) {
            if (port >= 1 && port <= 65535) {
                this.buildTarget.parentID = parentID;
                this.buildTarget.parental = parental;
                this.buildTarget.devicePassword = devicePassword;
                this.buildTarget.ipAddress = ipAddress;
                this.buildTarget.port = port;
                return this;
            }
            this.errorMessage += "port 端口号格式不正确\n";
            return this;
        }

        public Builder setVideoParams(int videoCodeID, int ppi, int frameRate, int rateType, int rateSize) {
            if (rateType != 1 && rateType != 2) {
                this.errorMessage += "rateType 码率类型 必须为固定码率(CBR); 2:可变码率(VBR)\n";
                return this;
            } else if (frameRate >= 0 && frameRate <= 99) {
                this.buildTarget.videoCodeID = videoCodeID;
                this.buildTarget.ppi = ppi;
                this.buildTarget.frameRate = frameRate;
                this.buildTarget.rateType = rateType;
                this.buildTarget.rateSize = rateSize;
                return this;
            } else {
                this.errorMessage += "frameRate 帧率 取值0-99\n";
                return this;
            }
        }

        public Builder setAudioParams(int audioCodeID, int sample, int bitRate) {
            this.buildTarget.audioCodeID = audioCodeID;
            this.buildTarget.sample = sample;
            this.buildTarget.bitRate = bitRate;
            return this;
        }

        public Builder setStreamTranType(int streamTranType) {
            this.buildTarget.streamTranType = streamTranType;
            return this;
        }

        public Builder setDebug(boolean isDebug) {
            this.buildTarget.isDebug = isDebug;
            return this;
        }

        public Builder setPlatformID(String platformID) {
            this.buildTarget.platformID = platformID;
            return this;
        }

        public Builder setDeviceStatesRate(int deviceStatesRate) {
            if (deviceStatesRate < 1000) {
                this.errorMessage = "基本信息上报频率过快" + deviceStatesRate;
            }
            this.buildTarget.deviceStatesRate = deviceStatesRate;
            return this;
        }

        public Builder setLocationRate(int locationRate) {
            if (locationRate < 1000) {
                this.errorMessage = "定位信息发送频率过快" + locationRate;
            }
            this.buildTarget.locationRate = locationRate;
            return this;
        }

        public Builder setPositionStopRate(int positionStopRate) {
            if (positionStopRate < 1) {
                this.errorMessage = "设备静止告警上报过快" + positionStopRate;
            }
            this.buildTarget.positionStopRate = positionStopRate * 60 * 1000;
            return this;
        }

        public Builder setAccountInfo(String account, String password) {
            this.buildTarget.account = account;
            this.buildTarget.password = password;
            return this;
        }

        public Builder setVideoChannelID(String videoChannelID) {
            this.buildTarget.videoChannelID = videoChannelID;
            return this;
        }

        public static String bytesToHexString(byte[] bArr) {
            StringBuilder sb = new StringBuilder("");
            if (bArr == null || bArr.length <= 0) {
                return null;
            }
            for (byte b : bArr) {
                String hexString = Integer.toHexString(b & UByte.MAX_VALUE);
                if (hexString.length() < 2) {
                    sb.append(0);
                }
                sb.append(hexString);
            }
            return sb.toString();
        }

        public Builder setVideoChannelName(String videoChannelName) {
            this.buildTarget.videoChannelName = videoChannelName;
            return this;
        }

        public Builder setVideoCodeID(int videoCodeID) {
            this.buildTarget.videoCodeID = videoCodeID;
            return this;
        }

        public Builder setAudioChannelName(String audioChannelName) {
            this.buildTarget.audioChannelName = audioChannelName;
            return this;
        }

        public Builder setAudioChannelID(String audioChannelID) {
            this.buildTarget.audioChannelID = audioChannelID;
            return this;
        }

        public Builder setAudioCodeID(int audioCodeID) {
            this.buildTarget.audioCodeID = audioCodeID;
            return this;
        }

        public Builder setSOSChannelID(String sosChannelID) {
            this.buildTarget.sosChannelID = sosChannelID;
            return this;
        }

        public Builder setSOSChannelName(String sosChannelName) {
            this.buildTarget.sosChannelName = sosChannelName;
            return this;
        }

        public Builder setAutoAnswer(boolean autoAnswer) {
            this.buildTarget.autoAnswer = autoAnswer;
            return this;
        }

        public Builder setAutoSyncConfig(boolean autoSyncConfig) {
            this.buildTarget.autoSyncConfig = autoSyncConfig;
            return this;
        }

        public Builder setUploadGps(boolean uploadGps) {
            this.buildTarget.uploadGps = uploadGps;
            return this;
        }
    }
}
